package com.study.factory;

import com.study.pojo.Company;
import org.springframework.beans.factory.FactoryBean;

public class CompanyFactory implements FactoryBean<Company> {

    private String companyInfo;

    public void setCompanyInfo(String companyInfo) {
        this.companyInfo = companyInfo;
    }

    @Override
    public Company getObject() throws Exception {
        String[] split = companyInfo.split(",");
        // 模拟创建复杂对象Company
        Company company = new Company();
        company.setName(split[0]);
        company.setAddress(split[1]);
        return company;
    }

    /**
     * 返回需要生成对象的类型
     */
    @Override
    public Class<?> getObjectType() {
        return Company.class;
    }

    /**
     * 判断是否为单例
     */
    @Override
    public boolean isSingleton() {
        return true;
    }
}
